import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../routes/routes.dart';

class ProfilePage extends StatelessWidget {
  const ProfilePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          // 自定义AppBar，更现代的设计
          SliverAppBar(
            expandedHeight: 200.0,
            floating: false,
            pinned: true,
            flexibleSpace: FlexibleSpaceBar(
              title: const Text('个人资料', 
                style: TextStyle(
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                ),
              ),
              background: Container(
                decoration: const BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.topCenter,
                    end: Alignment.bottomCenter,
                    colors: [Color(0xFFFF5A33), Color(0xFFFF7652)],
                  ),
                ),
              ),
            ),
            actions: [
              IconButton(
                icon: const Icon(Icons.settings),
                onPressed: () {
                  // 使用 Get.toNamed 跳转到设置页面
                  // 如果路由尚未定义，可以使用临时提示
                  ScaffoldMessenger.of(Get.context!).showSnackBar(
                    const SnackBar(content: Text('设置功能开发中')),
                  );
                },
              ),
            ],
          ),
          SliverToBoxAdapter(
            child: Column(
              children: [
                // 个人信息卡片
                _buildProfileCard(),
                
                // 统计数据卡片
                Card(
                  margin: const EdgeInsets.symmetric(horizontal: 16.0),
                  elevation: 2.0,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(12.0),
                  ),
                  child: Padding(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        _buildStatItem('帖子', '10'),
                        _buildDivider(),
                        _buildStatItem('关注', '128'),  // 新增关注人数统计
                        _buildDivider(),
                        _buildStatItem('粉丝', '256'),
                        _buildDivider(),
                        _buildStatItem('获赞', '1024'),
                      ],
                    ),
                  ),
                ),
                
                const SizedBox(height: 16.0),
                
                // 功能列表
                Card(
                  margin: const EdgeInsets.symmetric(horizontal: 16.0),
                  elevation: 2.0,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(12.0),
                  ),
                  child: Column(
                    children: [
                      _buildListTile('我的金币', '1000 Coins', Icons.monetization_on, 
                        () {
                          // 使用 Get.toNamed 跳转到金币列表页面
                          // 如果路由尚未定义，可以使用临时提示
                          ScaffoldMessenger.of(Get.context!).showSnackBar(
                            const SnackBar(content: Text('金币功能开发中')),
                          );
                        }),
                      const Divider(height: 1, indent: 56.0),
                      _buildListTile('我的帖子', '', Icons.article, 
                        () {
                          // 使用 Get.toNamed 跳转到我的帖子页面
                          // 如果路由尚未定义，可以使用临时提示
                          ScaffoldMessenger.of(Get.context!).showSnackBar(
                            const SnackBar(content: Text('我的帖子功能开发中')),
                          );
                        }),
                      const Divider(height: 1, indent: 56.0),
                      _buildListTile('系统反馈', '', Icons.feedback, 
                        () {
                          // 使用 Get.toNamed 跳转到反馈页面
                          // 如果路由尚未定义，可以使用临时提示
                          ScaffoldMessenger.of(Get.context!).showSnackBar(
                            const SnackBar(content: Text('反馈功能开发中')),
                          );
                        }),
                    ],
                  ),
                ),
                
                const SizedBox(height: 24.0),
              ],
            ),
          ),
        ],
      ),
    );
  }

  // 构建个人信息卡片
  Widget _buildProfileCard() {
    return Card(
      margin: const EdgeInsets.all(16.0),
      elevation: 2.0,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(16.0),
      ),
      child: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 头像部分 - 增加边框和阴影效果
            Container(
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                border: Border.all(color: const Color(0xFFFF5A33), width: 2),
                boxShadow: [
                  BoxShadow(
                    color: Colors.black.withOpacity(0.1),
                    blurRadius: 8,
                    offset: const Offset(0, 2),
                  ),
                ],
              ),
              child: const CircleAvatar(
                radius: 40,
                backgroundImage: NetworkImage('https://via.placeholder.com/80'),
              ),
            ),
            const SizedBox(width: 16.0),
            
            // 用户信息部分
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  // 昵称和性别
                  Row(
                    children: [
                      const Text(
                        'Nickname',
                        style: TextStyle(
                          fontSize: 22,
                          fontWeight: FontWeight.bold,
                          color: Color(0xFF333333),
                        ),
                      ),
                      const SizedBox(width: 8),
                      // 添加性别图标
                      Container(
                        padding: const EdgeInsets.all(4),
                        decoration: BoxDecoration(
                          color: Colors.blue[100],
                          borderRadius: BorderRadius.circular(4),
                        ),
                        child: const Icon(
                          Icons.male, // 或 Icons.female
                          color: Colors.blue, // 男性蓝色，女性可用粉色
                          size: 16,
                        ),
                      ),
                    ],
                  ),
                  const SizedBox(height: 4.0),
                  
                  // 用户ID
                  Container(
                    padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
                    decoration: BoxDecoration(
                      color: const Color(0xFFFFD7C5),
                      borderRadius: BorderRadius.circular(12.0),
                    ),
                    child: const Text(
                      'ID: 12345',
                      style: TextStyle(
                        color: Color(0xFFFF5A33),
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                  
                  // 添加简短个人签名
                  const SizedBox(height: 8.0),
                  const Text(
                    '这是我的个人签名，展示我的个性和风格~',
                    style: TextStyle(
                      color: Color(0xFF666666),
                      fontSize: 14,
                    ),
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildStatItem(String label, String count) {
    return Column(
      children: [
        Text(
          count,
          style: const TextStyle(
            fontSize: 18,  // 稍微减小字体大小
            fontWeight: FontWeight.bold,
            color: Color(0xFFFF5A33),
          ),
        ),
        const SizedBox(height: 2.0),  // 减小间距
        Text(
          label,
          style: const TextStyle(
            fontSize: 12,  // 减小标签字体大小
            color: Color(0xFF666666),
          ),
        ),
      ],
    );
  }
  
  Widget _buildDivider() {
    return Container(
      height: 30,
      width: 1,
      color: const Color(0xFFEEEEEE),
    );
  }
  
  Widget _buildListTile(String title, String subtitle, IconData icon, VoidCallback onTap) {
    return ListTile(
      leading: Container(
        padding: const EdgeInsets.all(8.0),
        decoration: BoxDecoration(
          color: const Color(0xFFFFD7C5),
          borderRadius: BorderRadius.circular(8.0),
        ),
        child: Icon(icon, color: const Color(0xFFFF5A33)),
      ),
      title: Text(
        title,
        style: const TextStyle(
          fontSize: 16,
          fontWeight: FontWeight.w500,
        ),
      ),
      subtitle: subtitle.isNotEmpty ? Text(subtitle) : null,
      trailing: const Icon(Icons.arrow_forward_ios, size: 16),
      onTap: onTap,
    );
  }
}